package com.auto.api.framework.builder;

import com.auto.api.framework.entity.BaseParamBO;
import com.auto.api.framework.entity.ContextParamBO;
import com.auto.api.framework.entity.ResponseBO;
import java.util.Objects;


/**
 * Description: 策略模式模板调用参数环境构造器
 *
 * @author liangshf
 * @date 2019-03-03
 */
//@Component
public class ContextParamBOBuilder {

    public Builder instance() {
        return new Builder();
    }

    public class Builder<Q,R extends ResponseBO> {
        private BaseParamBO<Q> paramBO;

        private R result;

        private Builder() {}

        public ContextParamBO build() {
            if (Objects.isNull(paramBO) || Objects.isNull(result)) {
                return null;
            }
            return new ContextParamBO(paramBO, result);
        }

        public Builder addParamChainBO(Q q, String strategyType) {
            paramBO = new BaseParamBO(q, strategyType,true);
            return this;
        }

        public Builder addParamFilterBO(Q q, String strategyType) {
            paramBO = new BaseParamBO(q, strategyType,false);
            return this;
        }

        public Builder addParamBO(Q q, String strategyType, String filterChainType) {
            paramBO = new BaseParamBO(q, strategyType, filterChainType);
            return this;
        }

        public Builder addResultBO(R result) {
            this.result = result;
            return this;
        }
    }
}